
$().ready(function () {
    var newBtnDA = MrcodeUi.Btn.newBtnDA($("#submit_btn"),false);
    newBtnDA.setDisabledMsg("请稍后...");

    $("#regist_form").validate({
        /*debug: true,  //调试*/
        rules: {
            account: {
                required: true,
                maxlength: 12,
                minlength: 6,
                remote: {
                    url: $contextPath + "/account/isregister/account",
                    type: "post"
                },
                isRightfulString:true
            },
            password: {
                required: true,
                maxlength: 12,
                minlength: 6
            },
            email: {
                required: true,
                maxlength: 32,
                email: true,
                remote: {
                    url: $contextPath + "/account/isregister/email",
                    type: "post"
                }
            }
        },
        messages: {
            account: {
                required: "账户不能为空",
                maxlength: "长度不能大于{0}",
                minlength: "长度不能小于{0}",
                remote: "该账户已被注册"
            },
            password: {
                required: "密码不能为空",
                maxlength: "长度不能大于{0}",
                minlength: "长度不能小于{0}"
            },
            email: {
                remote: "邮箱已被占用"
            }
        },
        errorElement: Comm.Ui.Jq_Validate.errorElement,
        errorClass: Comm.Ui.Jq_Validate.errorClass,
        errorPlacement: function (error, element) {
            Comm.Ui.Jq_Validate.errorPlacement(error, element);
        }, success: function (label) {
            Comm.Ui.Jq_Validate.success(label);
        },
        submitHandler: function (form) {
            newBtnDA.disabled();
            $.ajax({
                url: $contextPath + "/account/register/submit",
                data: $(form).serialize(),
                type: "POST",
                dataType: 'json',
                success: function (resultData) {
                    var success = resultData.success;
                    var info = resultData.info;
                    var data = resultData.data;
                    if (success) {
                        MrcodeUi.Alert.sx.success(data + " 注册成功");
                        setTimeout(function () {
                            window.location.href = "/account/login?account=" + data;
                        }, 2000);
                    } else {
                        MrcodeUi.Alert.sx.warning(info);
                        newBtnDA.active();
                    }
                },
                error: function (er) {
                    MrcodeUi.Alert.sx.warning("系统错误，请联系客服");
                    newBtnDA.active();
                }
            });
        }
    });
});
